package com.engine4cloud.tdf.education.convert;

import com.engine4cloud.tdf.common.core.constant.enums.EduActivitiesFileTypeEnum;
import com.engine4cloud.tdf.common.core.util.CodeUtils;
import com.engine4cloud.tdf.common.security.service.TdfUser;
import com.engine4cloud.tdf.education.dto.EduActivitiesFileDTO;
import com.engine4cloud.tdf.education.dto.query.EduActivitiesFileQueryDTO;
import com.engine4cloud.tdf.education.dto.result.EduActivitiesFileResultDTO;
import com.engine4cloud.tdf.education.entity.EduActivityFileEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;


@Mapper
public interface EduActivitiesFileConvert {
    EduActivitiesFileConvert INSTANCE = Mappers.getMapper(EduActivitiesFileConvert.class);

    @Mapping(target = "id", ignore = true)
    EduActivityFileEntity createTo(EduActivitiesFileDTO s);

    EduActivitiesFileResultDTO convert(EduActivityFileEntity s);

    default EduActivityFileEntity create(String activityCode, EduActivitiesFileTypeEnum fileType, EduActivitiesFileDTO s, TdfUser user) {
        EduActivityFileEntity entity = createTo(s);
        entity.setFileType(fileType);
        entity.setActivityCode(activityCode);
        entity.setCode(CodeUtils.entrustCode());
        entity.setTenantId(user.getTenantId());
        return entity;
    }

    default List<EduActivityFileEntity> createList(EduActivitiesFileQueryDTO dto, List<EduActivitiesFileDTO> fileList, TdfUser user) {
        return fileList.stream().map(file -> EduActivitiesFileConvert.INSTANCE.create(dto.getActivityCode(), dto.getFileType(), file, user)).toList();
    }
}
